package com.whty.fastdfs;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;

public class FastUploadFileTools {
	
	/*
	 * 1.base64 转二进制 流数组
	 */
	public static Map<String,Object> getByteInputStream(String base64Str){
//		ByteArrayInputStream in = null;
		Map<String,Object> map=new HashMap<String,Object>();
	    byte[] bytes = Base64.decodeBase64(base64Str); //将字符串转换为byte数组
//        in = new ByteArrayInputStream(bytes);

		map.put("fileInputStream", byteTostream(bytes));		
		map.put("fileLength", bytes.length);
		map.put("extension", "jpg");
		return map;
	}
	
	public static Map<String,Object> getWordByteInputStream(String base64Str){
//		ByteArrayInputStream in = null;
		Map<String,Object> map=new HashMap<String,Object>();
	    byte[] bytes = Base64.decodeBase64(base64Str); //将字符串转换为byte数组
//        in = new ByteArrayInputStream(bytes);

		map.put("fileInputStream", byteTostream(bytes));		
		map.put("fileLength", bytes.length);
		map.put("extension", "docx");
		return map;
	}
	
	/*
	 * 2、二进制流数组 转为流
	 */
	public static final InputStream byteTostream(byte[] buf) {  
        return new ByteArrayInputStream(buf);  
    }
	
	/*
	 * 
	 */

}
